<script>
export default {
  data() {
    return {
      show: false
    }
  },
  methods: {
    handScroll(dom) {
      if (!dom) {
        this.show = false
        return;
      }
      this.show = dom.scrollTop >= 500
    },
    handClick() {
      this.$bus.$emit('setMainScroll', 0)
    }
  },
  mounted() {
    this.$bus.$on('mainScroll', this.handScroll)
  },
  beforeDestroy() {
    this.$bus.$off('mainScroll', this.handScroll)
  }
}
</script>



<template>
  <div v-show="show" @click="handClick" class="to-top-container">Top</div>
</template>



<style lang='less' scoped>
@import '~@/styles/var.less';

.to-top-container {
  position: fixed;
  right: 5%;
  bottom: 5%;
  width: 50px;
  height: 50px;
  line-height: 50px;
  border-radius: 50%;
  background-color: @primary;
  text-align: center;
  color: @words;
  font-size: 18px;
  cursor: pointer;
}
</style>